package com.eclipse.organigram.model.entities;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

public class Category extends TreeElement {
	
	private String name;
	
	@JsonInclude(value=Include.NON_EMPTY)
	private List<Category> categories = new ArrayList<Category>();
	
	public String getName() {
		return name;
	}
	public List<Category> getCategories() {
		return categories;
	}
	
	@Override
	public Object[] getChildren() {
		List<Object> children = new ArrayList<Object>();
		children.addAll(categories);
		children.addAll(getTeam());
		return children.toArray();
	}
	
	public boolean hasChildren() {
		return !categories.isEmpty() || super.hasChildren();
	}
	
	public void add(Category category) {
		category.setParent(this);
		categories.add(category);
	}
	
	public int countPersons() {
		int count = getTeam().size();
		for (Person person : getTeam()) {
			count += person.getTeam().size();
		}
		for (Category category : categories) {
			count += category.countPersons();
		}
		return count;
	}
}